﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;

namespace LoadScript
{
    public partial class Frm_Config : Form
    {
        public Frm_Config()
        {
            InitializeComponent();

            txtBatPath.Text  =ConfigurationManager.AppSettings["batchFilePath"];
            txtConnStr .Text =ConfigurationManager.AppSettings["connectionString"];
            txtScriptPath.Text = ConfigurationManager.AppSettings["scriptFilePath"];
        }

        private void btnSelectScriptPath_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.ShowDialog();
            if (folderBrowserDialog1.SelectedPath.Length > 0)
            {
                txtScriptPath.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void btnSelectBatPath_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.ShowDialog();
            if (folderBrowserDialog1.SelectedPath.Length > 0)
            {
                txtBatPath.Text = folderBrowserDialog1.SelectedPath;
            }
            //ConfigurationManager.AppSettings["batchFilePath"] = folderBrowserDialog1.SelectedPath;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                SQLScriptLoaderRelease loader = new SQLScriptLoaderRelease(txtBatPath.Text.Trim(), txtConnStr.Text.Trim(),txtScriptPath .Text .Trim ());
                loader.CreateBatFile();
                loader.Load();
                loader.RunBatFile();
                MessageBox.Show("收工，开饭！");
                Application.Exit();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void Frm_Config1_Load(object sender, EventArgs e)
        {

        }
       
    }
}
